package o;

import com.google.android.exoplayer2.Format;
import com.huawei.appgallery.festivalanimation.particle.modifiers.SizeModifier;
import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;
import java.util.Collections;

public final class agg implements agc {
    private final agl ʻ = new agl(39, DnsConfig.MAX_CACHE_ENTRIES);
    private final agl ʼ = new agl(33, DnsConfig.MAX_CACHE_ENTRIES);
    private final agl ʽ = new agl(32, DnsConfig.MAX_CACHE_ENTRIES);
    private final agt ˊ;
    private final anc ˊॱ = new anc();
    private aef ˋ;
    private String ˎ;
    private boolean ˏ;
    private long ˏॱ;
    private final agl ͺ = new agl(40, DnsConfig.MAX_CACHE_ENTRIES);
    private a ॱ;
    private long ॱˊ;
    private final agl ॱॱ = new agl(34, DnsConfig.MAX_CACHE_ENTRIES);
    private final boolean[] ᐝ = new boolean[3];

    static final class a {
        private boolean ʻ;
        private boolean ʼ;
        private boolean ʽ;
        private boolean ˊ;
        private boolean ˊॱ;
        private long ˋ;
        private long ˎ;
        private final aef ˏ;
        private long ˏॱ;
        private long ͺ;
        private int ॱ;
        private boolean ॱॱ;
        private boolean ᐝ;

        public a(aef o_aef) {
            this.ˏ = o_aef;
        }

        public void ˊ() {
            this.ॱॱ = false;
            this.ᐝ = false;
            this.ʽ = false;
            this.ʻ = false;
            this.ʼ = false;
        }

        public void ˊ(long j, int i, int i2, long j2) {
            boolean z;
            boolean z2 = false;
            this.ᐝ = false;
            this.ʽ = false;
            this.ˎ = j2;
            this.ॱ = 0;
            this.ˋ = j;
            if (i2 >= 32) {
                if (!this.ʼ && this.ʻ) {
                    ˊ(i);
                    this.ʻ = false;
                }
                if (i2 <= 34) {
                    this.ʽ = !this.ʼ;
                    this.ʼ = true;
                }
            }
            if (i2 < 16 || i2 > 21) {
                z = false;
            } else {
                z = true;
            }
            this.ˊ = z;
            if (this.ˊ || i2 <= 9) {
                z2 = true;
            }
            this.ॱॱ = z2;
        }

        public void ॱ(byte[] bArr, int i, int i2) {
            if (this.ॱॱ) {
                int i3 = (i + 2) - this.ॱ;
                if (i3 < i2) {
                    this.ᐝ = (bArr[i3] & DnsConfig.MAX_CACHE_ENTRIES) != 0;
                    this.ॱॱ = false;
                    return;
                }
                this.ॱ += i2 - i;
            }
        }

        public void ˊ(long j, int i) {
            if (this.ʼ && this.ᐝ) {
                this.ˊॱ = this.ˊ;
                this.ʼ = false;
            } else if (this.ʽ || this.ᐝ) {
                if (this.ʻ) {
                    ˊ(((int) (j - this.ˋ)) + i);
                }
                this.ˏॱ = this.ˋ;
                this.ͺ = this.ˎ;
                this.ʻ = true;
                this.ˊॱ = this.ˊ;
            }
        }

        private void ˊ(int i) {
            this.ˏ.ˋ(this.ͺ, this.ˊॱ ? 1 : 0, (int) (this.ˋ - this.ˏॱ), i, null);
        }
    }

    public agg(agt o_agt) {
        this.ˊ = o_agt;
    }

    public void ˏ() {
        and.ˏ(this.ᐝ);
        this.ʽ.ˎ();
        this.ʼ.ˎ();
        this.ॱॱ.ˎ();
        this.ʻ.ˎ();
        this.ͺ.ˎ();
        this.ॱ.ˊ();
        this.ˏॱ = 0;
    }

    public void ˏ(ady o_ady, com.google.android.exoplayer2.extractor.ts.TsPayloadReader.a aVar) {
        aVar.ˊ();
        this.ˎ = aVar.ˎ();
        this.ˋ = o_ady.ˊ(aVar.ˏ(), 2);
        this.ॱ = new a(this.ˋ);
        this.ˊ.ˏ(o_ady, aVar);
    }

    public void ˋ(long j, int i) {
        this.ॱˊ = j;
    }

    public void ˊ(anc o_anc) {
        while (o_anc.ˊ() > 0) {
            int ˋ = o_anc.ˋ();
            int ॱ = o_anc.ॱ();
            byte[] bArr = o_anc.ˏ;
            this.ˏॱ += (long) o_anc.ˊ();
            this.ˋ.ˎ(o_anc, o_anc.ˊ());
            while (ˋ < ॱ) {
                int ॱ2 = and.ॱ(bArr, ˋ, ॱ, this.ᐝ);
                if (ॱ2 == ॱ) {
                    ˏ(bArr, ˋ, ॱ);
                    return;
                }
                int ॱ3 = and.ॱ(bArr, ॱ2);
                int i = ॱ2 - ˋ;
                if (i > 0) {
                    ˏ(bArr, ˋ, ॱ2);
                }
                int i2 = ॱ - ॱ2;
                long j = this.ˏॱ - ((long) i2);
                ˎ(j, i2, i < 0 ? -i : 0, this.ॱˊ);
                ˏ(j, i2, ॱ3, this.ॱˊ);
                ˋ = ॱ2 + 3;
            }
        }
    }

    public void ˋ() {
    }

    private void ˏ(long j, int i, int i2, long j2) {
        if (this.ˏ) {
            this.ॱ.ˊ(j, i, i2, j2);
        } else {
            this.ʽ.ˎ(i2);
            this.ʼ.ˎ(i2);
            this.ॱॱ.ˎ(i2);
        }
        this.ʻ.ˎ(i2);
        this.ͺ.ˎ(i2);
    }

    private void ˏ(byte[] bArr, int i, int i2) {
        if (this.ˏ) {
            this.ॱ.ॱ(bArr, i, i2);
        } else {
            this.ʽ.ˊ(bArr, i, i2);
            this.ʼ.ˊ(bArr, i, i2);
            this.ॱॱ.ˊ(bArr, i, i2);
        }
        this.ʻ.ˊ(bArr, i, i2);
        this.ͺ.ˊ(bArr, i, i2);
    }

    private void ˎ(long j, int i, int i2, long j2) {
        if (this.ˏ) {
            this.ॱ.ˊ(j, i);
        } else {
            this.ʽ.ॱ(i2);
            this.ʼ.ॱ(i2);
            this.ॱॱ.ॱ(i2);
            if (this.ʽ.ॱ() && this.ʼ.ॱ() && this.ॱॱ.ॱ()) {
                this.ˋ.ˎ(ˏ(this.ˎ, this.ʽ, this.ʼ, this.ॱॱ));
                this.ˏ = true;
            }
        }
        if (this.ʻ.ॱ(i2)) {
            this.ˊॱ.ॱ(this.ʻ.ॱ, and.ˋ(this.ʻ.ॱ, this.ʻ.ˊ));
            this.ˊॱ.ˎ(5);
            this.ˊ.ˋ(j2, this.ˊॱ);
        }
        if (this.ͺ.ॱ(i2)) {
            this.ˊॱ.ॱ(this.ͺ.ॱ, and.ˋ(this.ͺ.ॱ, this.ͺ.ˊ));
            this.ˊॱ.ˎ(5);
            this.ˊ.ˋ(j2, this.ˊॱ);
        }
    }

    private static Format ˏ(String str, agl o_agl, agl o_agl2, agl o_agl3) {
        int i;
        float f;
        Object obj = new byte[((o_agl.ˊ + o_agl2.ˊ) + o_agl3.ˊ)];
        System.arraycopy(o_agl.ॱ, 0, obj, 0, o_agl.ˊ);
        System.arraycopy(o_agl2.ॱ, 0, obj, o_agl.ˊ, o_agl2.ˊ);
        System.arraycopy(o_agl3.ॱ, 0, obj, o_agl.ˊ + o_agl2.ˊ, o_agl3.ˊ);
        anf o_anf = new anf(o_agl2.ॱ, 0, o_agl2.ˊ);
        o_anf.ˋ(44);
        int ˏ = o_anf.ˏ(3);
        o_anf.ˊ();
        o_anf.ˋ(88);
        o_anf.ˋ(8);
        int i2 = 0;
        for (i = 0; i < ˏ; i++) {
            if (o_anf.ˎ()) {
                i2 += 89;
            }
            if (o_anf.ˎ()) {
                i2 += 8;
            }
        }
        o_anf.ˋ(i2);
        if (ˏ > 0) {
            o_anf.ˋ((8 - ˏ) * 2);
        }
        o_anf.ॱ();
        int ॱ = o_anf.ॱ();
        if (ॱ == 3) {
            o_anf.ˊ();
        }
        int ॱ2 = o_anf.ॱ();
        int ॱ3 = o_anf.ॱ();
        if (o_anf.ˎ()) {
            int ॱ4 = o_anf.ॱ();
            int ॱ5 = o_anf.ॱ();
            int ॱ6 = o_anf.ॱ();
            int ॱ7 = o_anf.ॱ();
            i = (ॱ == 1 || ॱ == 2) ? 2 : 1;
            ॱ2 -= i * (ॱ4 + ॱ5);
            ॱ3 -= (ॱ == 1 ? 2 : 1) * (ॱ6 + ॱ7);
        }
        o_anf.ॱ();
        o_anf.ॱ();
        i = o_anf.ॱ();
        i2 = o_anf.ˎ() ? 0 : ˏ;
        while (i2 <= ˏ) {
            o_anf.ॱ();
            o_anf.ॱ();
            o_anf.ॱ();
            i2++;
        }
        o_anf.ॱ();
        o_anf.ॱ();
        o_anf.ॱ();
        o_anf.ॱ();
        o_anf.ॱ();
        o_anf.ॱ();
        if (o_anf.ˎ() && o_anf.ˎ()) {
            ˊ(o_anf);
        }
        o_anf.ˋ(2);
        if (o_anf.ˎ()) {
            o_anf.ˋ(8);
            o_anf.ॱ();
            o_anf.ॱ();
            o_anf.ˊ();
        }
        ॱ(o_anf);
        if (o_anf.ˎ()) {
            for (i2 = 0; i2 < o_anf.ॱ(); i2++) {
                o_anf.ˋ((i + 4) + 1);
            }
        }
        o_anf.ˋ(2);
        float f2 = 1.0f;
        if (o_anf.ˎ() && o_anf.ˎ()) {
            ˏ = o_anf.ˏ(8);
            if (ˏ == 255) {
                ˏ = o_anf.ˏ(16);
                i = o_anf.ˏ(16);
                if (!(ˏ == 0 || i == 0)) {
                    f2 = ((float) ˏ) / ((float) i);
                }
                f = f2;
            } else if (ˏ < and.ˎ.length) {
                f = and.ˎ[ˏ];
            } else {
                amz.ˏ("H265Reader", "Unexpected aspect_ratio_idc value: " + ˏ);
            }
            return Format.ˏ(str, "video/hevc", null, -1, -1, ॱ2, ॱ3, SizeModifier.STABLE_STATE_SCALE, Collections.singletonList(obj), -1, f, null);
        }
        f = 1.0f;
        return Format.ˏ(str, "video/hevc", null, -1, -1, ॱ2, ॱ3, SizeModifier.STABLE_STATE_SCALE, Collections.singletonList(obj), -1, f, null);
    }

    private static void ˊ(anf o_anf) {
        int i = 0;
        while (i < 4) {
            for (int i2 = 0; i2 < 6; i2 = (i == 3 ? 3 : 1) + i2) {
                if (o_anf.ˎ()) {
                    int min = Math.min(64, 1 << ((i << 1) + 4));
                    if (i > 1) {
                        o_anf.ˏ();
                    }
                    for (int i3 = 0; i3 < min; i3++) {
                        o_anf.ˏ();
                    }
                } else {
                    o_anf.ॱ();
                }
            }
            i++;
        }
    }

    private static void ॱ(anf o_anf) {
        int ॱ = o_anf.ॱ();
        int i = 0;
        int i2 = 0;
        boolean z = false;
        while (i < ॱ) {
            boolean ˎ;
            if (i != 0) {
                ˎ = o_anf.ˎ();
            } else {
                ˎ = z;
            }
            int i3;
            if (ˎ) {
                o_anf.ˊ();
                o_anf.ॱ();
                for (i3 = 0; i3 <= i2; i3++) {
                    if (o_anf.ˎ()) {
                        o_anf.ˊ();
                    }
                }
            } else {
                int ॱ2 = o_anf.ॱ();
                int ॱ3 = o_anf.ॱ();
                i2 = ॱ2 + ॱ3;
                for (i3 = 0; i3 < ॱ2; i3++) {
                    o_anf.ॱ();
                    o_anf.ˊ();
                }
                for (i3 = 0; i3 < ॱ3; i3++) {
                    o_anf.ॱ();
                    o_anf.ˊ();
                }
            }
            i++;
            z = ˎ;
        }
    }
}
